<?php $this->Html->addCrumb('Sales Tax'); ?>
<div id="result">	    
    <div class="global-title"><?php __('Sales Tax'); ?></div>
    <?php
    echo $this->Session->flash();
    if ($this->Session->check('Message.auth'))
        echo $this->Session->flash('auth');
    ?>
    <div class="div_content">
        <div>Use the Sales Tax table to enter tax rate you want to charge for each state, leave the field blank if you don't want to charge to specific state. Optionally, you
            can indicate whether you want to charge Sales Tax for Shipping and Handling.
        </div>
        <div style="background:#ccc;font-size: 15px; color: black; height: 26px; vertical-align: middle; padding-top: 4px; padding-left: 3px;">Currently Sales Tax applied on:</div>
        <table id="category_table" cellspacing="0" class="tablesorter">
            <thead>
                <tr>
                    <th width="50" style="height:25px;"><?php echo _('State'); ?></th>
                    <th width="70" style="height:25px;"><?php echo _('Sales Tax Rate'); ?></th>
                    <th width="120" style="height:25px;"><?php echo _('Sales Tax applied on'); ?></th>
                    <th width="160" style="height:25px;">Actions</th>

                </tr>
            </thead>
            <tbody>
                <?php
                $i = 0;
                //pr($salestaxes);
                foreach ($salestaxes as $salestax):
                    $class = null;
                    if ($i++ % 2 == 0) :
                        $class = ' class="alt"';
                        ?>
                        <tr id="row_<?php echo $salestax['Salestax']['id']; ?>">
                            <td class="alt"><?php echo $salestax['State']['name']; ?></td>
                            <td class="alt"><?php echo $salestax['Salestax']['rate']; ?>%  </td>
                            <td class="alt"><?php
                                    if ($salestax['Salestax']['taxappliedon'] == 1)
                                        echo "Product, Shipping & Handling";
                                    else
                                        echo "Product";
                                    ?>
                            </td>
                            <td align="center" class="alt">
                                <a href="javascript:void(0);" controller="salestaxes" action="edittax" title="Edit" ElmID="<?php echo $salestax['Salestax']['id']; ?>" onclick='showPop(this)' style="text-decoration:none">
                                 <?php echo $this->Html->image("edit_gray.png", array("alt" => "Edit", 'border' => '0')); ?>
                                </a>&nbsp;&nbsp;
                                <a href="javascript:void(0);" class="deletetax" rowid="<?php echo $salestax['Salestax']['id']; ?>" ><?php echo $this->Html->image("delete_gray.png", array("alt" => "Delete", 'border' => '0')); ?></a>                        
                            </td>
                        </tr>
                    <?php else: ?>
                        <tr id="row_<?php echo $salestax['Salestax']['id']; ?>">
                            <td><?php echo $salestax['State']['name']; ?></td>
                            <td><?php echo $salestax['Salestax']['rate']; ?>%</td>
                            <td><?php if ($salestax['Salestax']['taxappliedon'] == 1)
                                echo "Product, Shipping & Handling"; else
                                echo "Product"; ?>
                            </td>
                            <td align="center">
                                <a href="javascript:void(0);" controller="salestaxes" action="edittax" title="Edit" ElmID="<?php echo $salestax['Salestax']['id']; ?>" onclick='showPop(this)' style="text-decoration:none">
                                    <?php echo $this->Html->image("edit_yellow.png", array("alt" => "Edit", 'border' => '0')); ?>
                                </a>&nbsp;&nbsp;
                                <a href="javascript:void(0);" class="deletetax" rowid="<?php echo $salestax['Salestax']['id']; ?>" ><?php echo $this->Html->image("delete_red.png", array("alt" => "Delete", 'border' => '0')); ?></a>
                            </td>
                        </tr>
            <?php endif;
                endforeach; ?>
            <tbody>
        </table>
        <div class="paging">
            <div style="background:#ccc;font-size: 15px; color: black; height: 26px; vertical-align: middle; padding-top: 4px; padding-left: 3px;">
                Add Sales Tax
            </div>
            <div>
                <form method="post" id="suspendfrm" action="<?php echo Configure::read('base_url') . "salestaxes/add_seller"; ?>">
                    <table cellspacing="0" width="100%">
                        <tbody>
                            <tr>
                                <td>
                                    Apply
                                    <?php
                                    echo $this->Form->input('Salestax.rate', array('div' => false, 'label' => false, 'size' => 10, 'class' => 'required decimal', 'style' => 'text-align:right;'));
                                    ?>&nbsp;&nbsp;%
                                </td>
                                <td>
                                    Sales Tax on
                                    <?php echo $this->Form->input('Salestax.state_id', array('empty' => '--Select State--', 'div' => false, 'label' => false, 'class' => 'required')); ?>
                                </td>
                                <td>
<?php
echo $this->Form->input('Salestax.taxappliedon', array('type' => 'checkbox', 'div' => false, 'label' => false));
?>
                                    Also,apply sales tax to shipping & handling
                                </td>
                                <td colspan="2" align="left">
                                    <?php
                                    if (isset($this->data['product_id'])):
                                        echo $this->Form->input('Salestax.product_id', array('type' => 'hidden', 'value' => $this->data['product_id']));
                                    endif;
                                    ?>

                                    <input type="submit" class="button" name="button" id="button" value="Add" />

                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form></div>
        </div>
    </div>
    <div class="div_bottom"></div>
</div>

<!-- edit sidebar items here -->


<?php
echo $this->Html->css('table_css');
?>
<style type="text/css">
    td.alt {
        background: none repeat scroll 0 0 #EEEEEE;
        color: #797268;
        margin: 0;
        padding: 6px;
    }
    table.tablesorter tbody td {
        color: #3D3D3D;
        padding: 4px;
        vertical-align: top;
    }

    td {
        background: none repeat scroll 0 0 #FFFFFF;
        border-bottom: 1px solid #CCCCCC;
        border-right: 1px solid #CCCCCC;
        color: #000000;
        font-size: 12px;
        padding: 6px;
    }
</style>
<?php echo $html->script(array("jquery.pagination.js", "jquery.tablesorter.min.js", "jquery.tablednd.js", "jquery.validate.js")); ?>
<script type="text/javascript"> 
    var v = jQuery("#suspendfrm").validate({
        submitHandler: function(form) {
            jQuery(form).ajaxSubmit({
                target: "#result"
            });
        }
    });

    jQuery(document).ready(function(){
        jQuery("#category_table").tablesorter({headers: {3:{sorter: false}, 4:{sorter: false}}});
		
        //Domestic Shipping
        jQuery('tr td a.deletetax').live('click',function(){
            var rowid=jQuery(this).attr("rowid");
            if(confirm("Are you sure you want to delete this?")){
                jQuery.ajax({
                    type: 'GET',
                    url: baseurl+"salestaxes/deletesales/"+rowid,					
                    dataType: 'json',
                    success: function(data){
                        alert(data.msg);	
                        jQuery('#row_'+data.RowId).remove();						
                    }
                });
            }			
            return false;
        });
	
    });
</script>
<?php //echo $this->element('sql_dump');  ?>
